package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理和品牌有关的请求
 */
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;
    /**
     * 分页查询品牌分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("baseTrademark/{pageNum}/{pageSize}")
    public Result getBaseTrademarkPage(@PathVariable("pageNum") Long pageNum,
                                       @PathVariable("pageSize") Long pageSize){
        Page<BaseTrademark> page= new Page<>(pageNum,pageSize);
        //调用分页方法
        Page<BaseTrademark> result = baseTrademarkService.page(page);
        //前端全量接受分页
        return Result.ok(result);
    }

    /**
     * 添加品牌
     * @param baseTrademark
     * @return
     */
    @PostMapping("baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 根据id查询品牌
     * @param id
     * @return
     */
    @GetMapping("baseTrademark/get/{id}")
    public Result getBaseTrademarkById(@PathVariable("id") Long id){
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }

    /**
     * 修改品牌
     * @return
     */
    @PutMapping("baseTrademark/update")
    public Result updateTrademarkById(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result deleteTrademarkById(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 获取品牌列表
     * @return
     */
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

}
